<?php
require_once($application_folder."/controllers/navigator.php");
class Core extends navigator 
{

    function __construct()
    {
        parent::__construct(); 
    }

    function index($page='home',$sub='', $upsub= '')
    { 

        if(isset($_GET['id'])){
            $data['novost'] = $this->sitem->read($_GET['id']);
        }else{
            $data['novosti'] = $this->sitem->readAll('novosti', 5);
        }

        $this->core_site('site/'.$page, $data, $sub);        
    }  

    function uslovi()
    {
        $this->load->view('site/uslovi');
    }

    function aplikacija(){
        $this->test_mail();
    }

    function test_mail()
    {

        if((isset($_FILES['myfile']) && !empty($_FILES['myfile']['name']))){ 

            $this->load->library('upload'); 

            // set upload
            $config['upload_path'] = './tempatt/';
            $config['allowed_types'] = 'jpg|jpeg|doc';
            $config['max_size']    = '300';

            $this->upload->initialize($config);

            if ( ! $this->upload->do_upload('myfile'))
            {
                $error = $this->upload->display_errors();
                if($error=='<p>The filetype you are attempting to upload is not allowed.</p>'){
                    echo "Nije dozvoljen upload fajla sa ovom ekstenzijom.<br />";
                    echo "Molim dodajte aplikaciju preuzetu sa oficijelnog sajta. ";
                }else{
                    echo $error;
                }
            }
            else
            {
                $upload_info = $this->upload->data();

                $this->load->library('email');

                $this->email->clear(TRUE);

                $config['protocol'] = 'sendmail';
                $config['mailpath'] = '/usr/sbin/sendmail';
                $config['charset'] = 'utf-8';
                $config['wordwrap'] = TRUE;
                $config['mailtype'] = 'html';
                $config['smtp_host'] = 'localhost';
                $this->email->initialize($config);

                $this->email->from('www.montenegrolines.com', 'Montenegrolines');
                $this->email->to('barplov@t-com.me');
                $this->email->cc('ikukic@yahoo.com');

                $this->email->subject('Prijava za posao');
                $this->email->message('U prilogu je prijava za posao poslata preko sajta.');

                $this->email->attach($upload_info['full_path']);



                if ($this->email->send()) {
                    echo("<p>Aplikacija je poslata!<br /><a href='".base_url()."posao'>OK</a></p>");
                } else {
                    echo("<p>Greska pri slanju aplikacije...</p>");
                }

                //echo $this->email->print_debugger();
            }
        }else{
            echo "Molim odaberite fajl!";
        }

    }

}